/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webaccess.retailws.DAO;

import com.mysql.jdbc.Connection;
import com.webaccess.retailws.db.DBConnection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

/**
 *
 * @author Owner
 */
public class CommonDAO {

    DBConnection dbc = null;
    Connection conn = null;
    ResultSet rs = null;
    String result = null;
    StringBuffer myQuery = null;
    UserInfoDAO userDAO = null;
    List categList = new ArrayList();

    public CommonDAO() {
        try {
            dbc = new DBConnection();
            //  conn = (Connection) dbc.getConnection();

        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public LinkedHashMap getStatusLHMap() {
        LinkedHashMap statusLHMap = new LinkedHashMap();
        myQuery = new StringBuffer();
        myQuery.append("SELECT 	`status_id`, 	`status`	FROM 	`retailws`.`status`");
        statusLHMap = getData(myQuery.toString());
        return statusLHMap;
    }

    public LinkedHashMap getData(String myQuery) {
        LinkedHashMap dataMap = new LinkedHashMap();
        try {
            if (conn == null || conn.isClosed() ) {
                conn = (Connection) dbc.getConnection();
            }
            rs = dbc.executeQuery(conn, myQuery);
            if (rs != null) {
                String rsValue = String.valueOf(rs);
                if (!rsValue.equalsIgnoreCase("Result set representing update count of 0")) {
                    while (rs.next()) {
                        dataMap.put(rs.getString(1), rs.getString(2));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                dbc.freeResultSet(rs);
                dbc.freeConnection(conn);
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return dataMap;
        }
    }
}
